from typing import List


class Solution:
    def fourSumCount(
        self, A: List[int], B: List[int], C: List[int], D: List[int]
    ) -> int:
        d = [A, B, C, D]
        res = 0
        length = len(A)

        def backtrack(x, y, s):
            nonlocal res
            print(x, y, s)
            if x == 4 and s == 0:
                res += 1

            for i in range(x, 4):
                for j in range(length - 1):
                    backtrack(i + 1, j + 1, s + d[i][j])

        backtrack(0, 0, 0)

        return res


if __name__ == "__main__":
    A = [1, 2]
    B = [-2, -1]
    C = [-1, 2]
    D = [0, 2]
    res = Solution().fourSumCount(A, B, C, D)
    print(res)
